package com.CampusLife.controller;

import  com.CampusLife.bean.LostComment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import  com.CampusLife.service.ILostCommentService;
import  com.CampusLife.until.DataTime;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/lostComment")
public class LostCommentController {
    @Resource
    private ILostCommentService iLostCommentService;
    @RequestMapping("/queryAll")
    public  String  findall(Integer l_id,Model model){
        List<LostComment> lostComments=iLostCommentService.queryAll();
        model.addAttribute("lostComments",lostComments);
        return  "/home.jsp";

    }
    @RequestMapping("/add")
    public String addcomment(String comment_txt,int l_id, HttpSession httpSession, Model model){
        LostComment lostComment=new LostComment();
        lostComment.setComment_txt(comment_txt);
       int i=(int) httpSession.getAttribute("id");
        lostComment.setId(i);
        lostComment.setL_id(l_id);
        DataTime  dataTime=new DataTime();
        String data=dataTime.gettime();
        lostComment.setTime(data);
        iLostCommentService.add(lostComment);
        return "";
    }
    //根据商品查询评论
    @RequestMapping("/ByLostid")
    public  String ByLostid(Integer l_id,Model model){
      List<LostComment> lostComments= iLostCommentService.queryById(l_id);
      model.addAttribute("lostComments",lostComments);
      return "";
    }
    @RequestMapping("/delete")
    public  String delete(Integer id,HttpSession httpSession){
        iLostCommentService.delete(id);
        return "";
    }
}
